package com.homework.ch11;

import java.io.*;
import java.util.Scanner;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/16
 * @Description:
 */


public class Test {

    public static void main(String[] args) throws IOException {
        File file = new File("trial.txt");

        // 读取次数
        int count = 0;
        if (file.exists()) {
            FileInputStream fis = new FileInputStream(file);
            StringBuilder sb = new StringBuilder();
            int data;
            while ((data = fis.read()) != -1) {
                sb.append((char) data);
            }
            fis.close();
            count = Integer.parseInt(sb.toString());
        }

        // 检查次数
        if (count >= 10) {
            System.out.println("试用结束！请购买正版。");
            return;
        }

        // 保存次数
        count++;
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(String.valueOf(count).getBytes());
        fos.close();

        // 运行软件
        System.out.println("第 " + count + " 次使用");
        System.out.println("软件运行中...");


    }
}